/**
 * 
 */
package qy.jalgotrade.strategy.position;

import qy.jalgotrade.broker.Order;
import qy.jalgotrade.broker.OrderEvent;

/**
 * @author qy
 *
 */
public abstract class PositionState {

	public abstract void onEnter(Position position);

	/**
	 * Raise an exception if an order can't be submitted in the current state.
	 * 
	 * @param position
	 * @param order
	 */
	public abstract void canSubmitOrder(Position position, Order order) throws Exception;

	/**
	 * 
	 * @param position
	 * @param orderEvent
	 * @throws Exception
	 */
	public abstract void onOrderEvent(Position position, OrderEvent orderEvent) throws Exception;

	/**
	 * 
	 * @param position
	 * @return
	 */
	public abstract boolean isOpen(Position position);

	/**
	 * 
	 * @param position
	 * @throws Exception
	 */
	public void exit(Position position) throws Exception {

		exit(position, Double.NaN, Double.NaN, false);
	}

	/**
	 * 
	 * @param position
	 * @param stopPrice
	 * @throws Exception
	 */
	public void exit(Position position, double stopPrice) throws Exception {

		exit(position, stopPrice, Double.NaN, false);
	}

	/**
	 * 
	 * @param position
	 * @param stopPrice
	 * @param limitPrice
	 * @throws Exception
	 */
	public void exit(Position position, double stopPrice, double limitPrice) throws Exception {

		exit(position, stopPrice, limitPrice, false);
	}

	/**
	 * 
	 * @param position
	 * @param stopPrice
	 * @param limitPrice
	 * @param goodTillCanceled
	 * @throws Exception
	 */
	public abstract void exit(Position position, double stopPrice, double limitPrice, boolean goodTillCanceled)
	        throws Exception;
}
